<?php
namespace app\controller;

use think\Request;
use app\common\UtilService;
use app\model\BookType as BookTypeModel;

class BookType extends Base
{
	public function index(Request $request)
	{
		return view();
	}

	/**
	 * [getAjaxTypeList 异步获取分类列表,包含子类]
	 * @since  2022-04-22
	 * @author Dai哥
	 * @param  Request    $request [description]
	 * @return [type]              [description]
	 */
	public function getAjaxTypeAllList(Request $request)
	{
		try {

			$param = UtilService::getMore([
	            ['pid', '0'],
	            ['is_som', 'Y'],
	        ]);

			# 父分类
			$pre_list = BookTypeModel::getBookTypeList(['pid' => $param['pid']]);

			# 全部子类
			$som_list = BookTypeModel::getBookTypeList(['is_som' => 'Y']);

			$arr = array(
				'pre_list' => $pre_list->toArray(),
				'som_list' => $som_list->toArray(),
			);

			return success($arr, '获取成功');
	        
        } catch (\Exception $e) {

            // 这是进行异常捕获
            return error($e->getMessage());
        }
	}

	/**
	 * [getAjaxTypeSomList 根据父类获取子类]
	 * @since  2022-04-22
	 * @author Dai哥
	 * @param  Request    $request [description]
	 * @return [type]              [description]
	 */
	public function getAjaxTypeSomList(Request $request)
	{
		try {

			$param = UtilService::getMore([
	            ['pid', ''],
	            ['is_som', ''],
	        ]);

			# 父分类
			$list = BookTypeModel::getBookTypeList($param);

			return success($list, '获取成功');
	        
        } catch (\Exception $e) {

            // 这是进行异常捕获
            return error($e->getMessage());
        }
	}
}